package com.ygu.Enter3;

import com.ygu.charpter2_reverselist.level1.ReverseList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class monotonyNum {

        public static void main(String[] args) {
            int[] originalArr1 = {0, 2, 2, 2, 2, 2, 5};
            int[] result1 = removeDuplicates(originalArr1);
            for (int i = 0; i < result1.length; i++) {
                System.out.print(result1[i] + " ");
            }
            // 输出：3 4 5
        }


    public static int[] removeDuplicates(int[] arr) {
        HashMap<Integer, Integer> map = new HashMap<>();
        List<Integer> uniqueList = new ArrayList<>();

        for (int num : arr) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }

        for (int num : arr) {
            if (map.get(num) == 1) {
                uniqueList.add(num);
            }
        }

        int[] result = new int[uniqueList.size()];
        for (int i = 0; i < uniqueList.size(); i++) {
            result[i] = uniqueList.get(i);
        }

        return result;
    }
}
